<?php

namespace app\home\controller;

use app\common\controller\Home;
use think\facade\Cache;
use think\facade\Db;
use think\facade\View;
use app\common\model\User;

class Test extends Home
{
    public $test_usdt = '0x337610d27c682E347C9cD60BD4b3b107C9d34dDd';
    public $usdt = '';
    public $address = '0xE50Dc67A2704eB128E2E60Ac014042D758F77533';

    public function test0(){
        $contract_address = '0x55d398326f99059ff775485246999027b3197955';
        $address = '0xE50Dc67A2704eB128E2E60Ac014042D758F77533';
        $bsc = new \Bsc();
        $bsc->transactionReceipt('0x1c3b35865250c4dbc95884954ad7a67a8f93f88349510a84b0299e15afdd16b0');die;
//        $b = $bsc->balance($this->address);
        $b = $bsc->contractBalance($address,$contract_address);
        echo $b;die;
//        $bsc->contractDecimal('0x55d398326f99059ff775485246999027b3197955');
    }

    public function test1()
    {
        $uri = 'https://bsc-dataseed1.defibit.io/'; // Mainnet
//        $uri = 'https://data-seed-prebsc-2-s1.binance.org:8545/';// Testnet
        $api = new \Binance\NodeApi($uri);
        $res = $api->bnbBalance('0xE50Dc67A2704eB128E2E60Ac014042D758F77533');
        $bnb = new \Binance\Bnb($api);
        // 交易转账(离线签名)
        $address = '0x1667ca2c72d8699f0c34c55ea00b60eef021be3a';
        $bnb->bnbBalance($address);
        $from = '0x1667ca2c72d8699f0c34c55ea00b60eef021be3a';
        $to = '0x1667ca2c72d8699f0c34c55ea00b60eef021****';
        $amount = 0.1;
        $bnb->transfer($from, $to, $amount);
        dump($res);die;

# Method 2 : Bscscan Api
        $apiKey = 'QVG2GK41ASNSD21KJTXUAQ4JTRQ4XUQZCX';
        $api = new \Binance\BscscanApi($apiKey);

        $address = '0xE50Dc67A2704eB128E2E60Ac014042D758F77533';
        $bnbWallet = new \Binance\Bnb($api);
        $bnbBalance = $bnbWallet->bnbBalance($address);
        dump($bnbBalance);die;

        $config = [
            'contract_address' => '0x55d398326f99059fF775485246999027B3197955', // USDT BEP20
            'decimals' => 18,
        ];
        $bep20Wallet = new \Binance\BEP20($api, $config);
        $bep20Balance = $bep20Wallet->balance($address);
    }

    public function test2(){
        $address = '0xE50Dc67A2704eB128E2E60Ac014042D758F77533';
        $address = '0xE9AE3261a475a27Bb1028f140bc2a7c843318afD';
        $bssc = new \Bsc();
        $bssc->balance($address);
    }
}